/*manager.c*/
#include "cineplex.h"

void Manager_Scheduler()
{
	agentsStarted = agentsStarted + 1;
	/*printf("%s  -  %s\n", myName, state);*/
	Wait(initCond, initLock);
	manager.runScheduler = runSchedulers;
	do
	{
		if(manager.state == IDLE)
		{
			Manager_IdleAction();
		}else if(manager.state == AVAILABLE)
		{
			Manager_AvailAction();
		}else if(manager.state == STARTMOVIE)
		{
			Manager_StartMovie();
		}else if(manager.state == DECIDECASHCHECK)
		{
			Manager_DecideCC();
		}else if(manager.state == BACKTOCHECK)
		{
			Manager_BackToCheck();
		}else if(manager.state == BACKTOCASH)
		{
			Manager_BackToCash();
		}else if(manager.state == CHECKASKTIXCLERKS)
		{
			Manager_ChATC();
		}else if(manager.state == CHECKWAITTIXCLERKS)
		{
			Manager_ChWTC();
		}else if(manager.state == CHECKHANDLETIXCLERKS)
		{
			Manager_ChHTC();
		}else if(manager.state == CHECKSENDTIXCLERKS)
		{
			Manager_ChSTC();
		}else if(manager.state == CHECKASKFOODCLERKS)
		{
			Manager_ChAFC();
		}else if(manager.state == CHECKWAITFOODCLERKS)
		{
			Manager_ChWFC();
		}else if(manager.state == CHECKHANDLEFOODCLERKS)
		{
			Manager_ChHFC();
		}else if(manager.state == CHECKSENDFOODCLERKS)
		{
			Manager_ChSFC();
		}else if(manager.state == CHECKASKTIXTAKERS)
		{
			Manager_ChATT();
		}else if(manager.state == CHECKWAITTIXTAKERS)
		{
			Manager_ChWTT();
		}else if(manager.state == CHECKHANDLETIXTAKERS)
		{
			Manager_ChHTT();
		}else if(manager.state == CHECKSENDTIXTAKERS)
		{
			Manager_ChSTT();
		}else if(manager.state == CASHASKTIXCLERKS)
		{
			Manager_CaATC();
		}else if(manager.state == CASHWAITTIXCLERKS)
		{
			Manager_CaWTC();
		}else if(manager.state == CASHASKFOODCLERKS)
		{
			Manager_CaAFC();
		}else if(manager.state == CASHWAITFOODCLERKS)
		{
			Manager_CaWFC();
		}else if(manager.state == CASHCLEARTIXTAKERS)
		{
			Manager_CaCTT();
		}else if(manager.state == COMPLETED)
		{
			manager.runScheduler = 0;
			Exit(0);
		}
		Yield();
	} while(manager.runScheduler);
}

struct Message Manager_GetMessage(int name)
{
	/*this will be the null output*/
	manager.tempMsg.name = NullMsg;
	manager.tempMsg.sender = NullMsg;
	
	Acquire(loopLock);
	for(i = 0; i < manager.numMsgs; i++)
	{
		if(manager.msgList[i].name == name)
		{
			manager.tempMsg.name = name;
			manager.tempMsg.sender = manager.msgList[i].sender;
			manager.numMsgs = manager.numMsgs - 1;
			break;
		}
	}
	for(k = i; k < MAX_TIX_CLERKS + MAX_FOOD_CLERKS - 1; k++)
	{
		/*movin on up*/
		manager.msgList[k].name = manager.msgList[k+1].name;
		manager.msgList[k].sender = manager.msgList[k+1].sender;
	}
	manager.msgList[MAX_TIX_CLERKS + MAX_FOOD_CLERKS - 1].name = NullMsg;
	manager.msgList[MAX_TIX_CLERKS + MAX_FOOD_CLERKS - 1].sender = NullMsg;
	Release(loopLock);
		
	return manager.tempMsg;
}

void Manager_IdleAction()
{
	/* printf("Customers still running: %d\n",cinema->customersRunning);*/
	if(!customersRunning)
	{
		manager.state = COMPLETED;
		return;
	}
	/*IterList* endMessage = msgList->Find("MovieOver");*/
	Manager_GetMessage(MovieOver);
	if(manager.tempMsg.sender != NullMsg)
	{
		/*printf("%s received Movie Over",myName);*/
		manager.moviePlaying = 0;
	}
	
	/*if(cinema->testPattern == 4)
	{
		manager.state = "CheckAskTixClerks";
		return;
	}*/
	
	if(!manager.moviePlaying && seatsFilled == 0)
	{
		if(getRandPercent() < 50)
		{
			manager.state = STARTMOVIE;
		}else{
			manager.state = DECIDECASHCHECK;
		}
	}else
	{
		manager.state = DECIDECASHCHECK;
	}
}

void Manager_AvailAction()
{
	/* printf("Customers still running: %d\n",cinema->customersRunning);*/
	/*IterList* endMessage = msgList->Find("MovieOver");*/
	Manager_GetMessage(MovieOver);
	if(manager.tempMsg.sender != NullMsg)
	{
		/*printf("%s received Movie Over",myName);*/
		manager.moviePlaying = 0;
	}
	if(!manager.moviePlaying && seatsFilled == 0)
	{
		if(getRandPercent() < 50)
		{
			manager.state = STARTMOVIE;
		}else{
			if(manager.checkLoop) manager.state = BACKTOCHECK;
			else if(manager.cashLoop) manager.state = BACKTOCASH;
		}
	}else
	{
		if(manager.checkLoop) manager.state = BACKTOCHECK;
		else if(manager.cashLoop) manager.state = BACKTOCASH;
	}
}

void Manager_StartMovie()
{
	/*cinema->tech->SendMessage("StartMovie", 0);*/
	/*cinema->lobby->SendMessage("NewMovieStarting",0);*/
	SendMessage(T_MOVIETECH, 0, StartMovie, 0);
	SendMessage(T_LOBBY, 0, NewMovieStarting, 0);
	letPeopleIn = 1;
	manager.moviePlaying = 1;
	/*printf("Manager is telling the MovieTechnnician to start the movie.\n");*/
	if(manager.checkLoop || manager.cashLoop) manager.state = AVAILABLE;
	else manager.state = IDLE;
}

void Manager_DecideCC()
{
	/*clerks->AppendMeTo(checkQueue);*/
	manager.checkQueueSize = NUM_TIX_CLERKS + NUM_FOOD_CLERKS + NUM_TIX_TAKERS;
	manager.msgsToSend = NUM_TIX_CLERKS;
	manager.repliesWaiting = NUM_TIX_CLERKS;
	manager.cgSize = 0;
	/*currentGroup->Clear();*/
	
	if(getRandPercent() < 60)
	{
		manager.checkLoop = 1;
		manager.cashLoop = 0;
		manager.state = CHECKASKTIXCLERKS;
	}
	else
	{
		manager.cashLoop = 1;
		manager.checkLoop = 0;
		manager.state = CASHASKTIXCLERKS;
	}
}

void Manager_BackToCheck()
{
	manager.cgSize = 0;
	if(manager.checkQueueSize > NUM_TIX_TAKERS){
		manager.state = CHECKASKFOODCLERKS;
		manager.msgsToSend = NUM_FOOD_CLERKS;
		manager.repliesWaiting = NUM_FOOD_CLERKS;
	}else{
		manager.state = CHECKASKTIXTAKERS;
		manager.msgsToSend = NUM_TIX_TAKERS;
		manager.repliesWaiting = NUM_TIX_TAKERS;
	}
}

void Manager_BackToCash()
{
	manager.cgSize = 0;
	if(manager.checkQueueSize > NUM_TIX_TAKERS){
		manager.state = CASHASKFOODCLERKS;
		manager.msgsToSend = NUM_FOOD_CLERKS;
		manager.repliesWaiting = NUM_FOOD_CLERKS;
	}else{
		manager.state = CASHCLEARTIXTAKERS;
	}
}

void Manager_ChATC()
{
	manager.replyTo = manager.msgsToSend-1;
	/*((TicketClerk*)replyTo)->SendMessage("WhatIsStatus", 1, this);*/
	SendMessage(T_TICKETCLERK, manager.replyTo, WhatIsStatus, 0);
	manager.msgsToSend = manager.msgsToSend - 1;
	if(manager.msgsToSend == 0){
		manager.state = CHECKWAITTIXCLERKS;
	}
}

void Manager_ChWTC()
{
	Acquire(manager.msgLock);
	/*IterList* clerkMsg = msgList->Find("NumInLine");*/
	Manager_GetMessage(NumInLine);
	if(manager.tempMsg.sender != NullMsg)
	{
		Release(manager.msgLock);
		/*currentGroup->Append(clerkMsg->Get(0));*/
		manager.currentGroup[manager.cgSize] = manager.tempMsg.sender;
		manager.lineLengths[manager.cgSize] = Line_getSize(T_TICKETCLERK, manager.tempMsg.sender);
		manager.repliesWaiting = manager.repliesWaiting - 1;		
		if(manager.repliesWaiting == 0)
		{
			Acquire(tixLinesLock);
			manager.state = CHECKHANDLETIXCLERKS;
		}
	}else{
		Wait(manager.sleepCon, manager.msgLock);
	}
}

void Manager_ChHTC()
{
	/*Build Outgoing Queue*/
	/*indices of changed clerk*/
	int changedClerk=-1;
	int currLen = 0;
	int currTC;
	Acquire(loopLock);
	for(i = 0; i < NUM_TIX_CLERKS; i++)
	{	
		currTC = manager.currentGroup[i];
		currLen = manager.lineLengths[i];
		
		/*printf("Curr line length %d\n",currLen);*/
		
		if(currLen == 0 && changedClerk == -1)
		{
			if(getRandPercent() < 20)
			{
				/*outgoing->Append("GoOnBreak",0);*/
				manager.outgoing[i].name = GoOnBreak;
				manager.outgoing[i].sender = 0;
				changedClerk = i;
			}else{
				/*outgoing->Append("Okay",0);*/
				manager.outgoing[i].name = Okay;
				manager.outgoing[i].sender = 0;
			}
		}
		else if(currLen == -1 && changedClerk == -1)
		{
			/*printf("BREEEEEEEEEEEEEEEEEAK\n");*/
			for(k = 0; k < NUM_TIX_CLERKS; k++) /*see if anyone is overfull*/
			{
				if(i==k) continue;
				if(manager.lineLengths[k] > 5)/*if another line has more than 5 in it*/
				{
					/*outgoing->Append("ComeOffBreak",0);*/
					manager.outgoing[i].name = ComeOffBreak;
					manager.outgoing[i].sender = 0;
					changedClerk = i;
					break;
				}
			}
			/*no one overfull*/
			if(changedClerk == -1)
			{
				/*outgoing->Append("Okay",0);*/
				manager.outgoing[i].name = Okay;
				manager.outgoing[i].sender = 0;
			}
		}
		else if(currLen < 3 && changedClerk == -1)
		{
			for(k = 0; k < NUM_TIX_CLERKS; k++) /*see if anyone else is on duty*/
			{
				if(i==k) continue;
				if(manager.lineLengths[k] > 0) /*if another is working and can't be put on break*/
				{
					if(getRandPercent() < 20)
					{
						/*outgoing->Append("GoOnBreak",0);*/
						manager.outgoing[i].name = GoOnBreak;
						manager.outgoing[i].sender = 0;
						changedClerk = i;
						break;
					}
				}
			}
			if(changedClerk == -1)
			{
				/*outgoing->Append("Okay",0);*/
				manager.outgoing[i].name = Okay;
				manager.outgoing[i].sender = 0;
			}
		}else
		{
			manager.outgoing[i].name = Okay;
			manager.outgoing[i].sender = 0;
		}
	}
	Release(loopLock);
	
	manager.msgsToSend = NUM_TIX_CLERKS;
	manager.state = CHECKSENDTIXCLERKS;
}

void Manager_ChSTC()
{
	if(manager.cgSize == 0)
	{
		manager.state = AVAILABLE;
		Release(tixLinesLock);
	}else{
		manager.replyTo = manager.currentGroup[manager.cgSize-1];
		if(manager.outgoing[manager.cgSize-1].name == GoOnBreak)
		{
			/*printf("Manager has told TicketClerk %s to go on break.\n",((TicketClerk*)replyTo)->myName);*/
		}
		/*((TicketClerk*)replyTo)->SendMessage(outgoing->GetName(0), 0);*/
		/*outgoing->Pop(0);*/
		SendMessage(T_TICKETCLERK, manager.replyTo, manager.outgoing[manager.cgSize-1].name, 0);
		manager.cgSize = manager.cgSize - 1;
		manager.checkQueueSize = manager.checkQueueSize -1;
	}
}

void Manager_ChAFC()
{
	manager.replyTo = manager.msgsToSend-1;
	/*((TicketClerk*)replyTo)->SendMessage("WhatIsStatus", 1, this);*/
	SendMessage(T_FOODCLERK, manager.replyTo, WhatIsStatus, 0);
	manager.msgsToSend = manager.msgsToSend - 1;
	if(manager.msgsToSend == 0){
		manager.state = CHECKWAITFOODCLERKS;
	}
}

void Manager_ChWFC()
{
	Acquire(manager.msgLock);
	/*IterList* clerkMsg = msgList->Find("NumInLine");*/
	Manager_GetMessage(NumInLine);
	if(manager.tempMsg.sender != NullMsg)
	{
		Release(manager.msgLock);
		/*currentGroup->Append(clerkMsg->Get(0));*/
		manager.currentGroup[manager.cgSize] = manager.tempMsg.sender;
		manager.lineLengths[manager.cgSize] = Line_getSize(T_FOODCLERK, manager.tempMsg.sender);
		manager.repliesWaiting = manager.repliesWaiting - 1;		
		if(manager.repliesWaiting == 0)
		{
			Acquire(foodLinesLock);
			manager.state = CHECKHANDLEFOODCLERKS;
		}
	}else{
		Wait(manager.sleepCon, manager.msgLock);
	}
}

void Manager_ChHFC()
{
	/*Build Outgoing Queue*/
	/*indices of changed clerk*/
	int changedClerk=-1;
	int currLen = 0;
	int currFC;
	Acquire(loopLock);
	for(i = 0; i < NUM_FOOD_CLERKS; i++)
	{	
		currFC = manager.currentGroup[i];
		currLen = manager.lineLengths[i];
		
		/*printf("Curr line length %d\n",currLen);*/
		
		if(currLen == 0 && changedClerk == -1)
		{
			if(getRandPercent() < 20)
			{
				/*outgoing->Append("GoOnBreak",0);*/
				manager.outgoing[i].name = GoOnBreak;
				manager.outgoing[i].sender = 0;
				changedClerk = i;
			}else{
				/*outgoing->Append("Okay",0);*/
				manager.outgoing[i].name = Okay;
				manager.outgoing[i].sender = 0;
			}
		}
		else if(currLen == -1 && changedClerk == -1)
		{
			/*printf("BREEEEEEEEEEEEEEEEEAK\n");*/
			for(k = 0; k < NUM_FOOD_CLERKS; k++) /*see if anyone is overfull*/
			{
				if(i==k) continue;
				if(manager.lineLengths[k] > 5)/*if another line has more than 5 in it*/
				{
					/*outgoing->Append("ComeOffBreak",0);*/
					manager.outgoing[i].name = ComeOffBreak;
					manager.outgoing[i].sender = 0;
					changedClerk = i;
					break;
				}
			}
			/*no one overfull*/
			if(changedClerk == -1)
			{
				/*outgoing->Append("Okay",0);*/
				manager.outgoing[i].name = Okay;
				manager.outgoing[i].sender = 0;
			}
		}
		else if(currLen < 3 && changedClerk == -1)
		{
			for(k = 0; k < NUM_FOOD_CLERKS; k++) /*see if anyone else is on duty*/
			{
				if(i==k) continue;
				if(manager.lineLengths[k] > 0) /*if another is working and can't be put on break*/
				{
					if(getRandPercent() < 20)
					{
						/*outgoing->Append("GoOnBreak",0);*/
						manager.outgoing[i].name = GoOnBreak;
						manager.outgoing[i].sender = 0;
						changedClerk = i;
						break;
					}
				}
			}
			if(changedClerk == -1)
			{
				/*outgoing->Append("Okay",0);*/
				manager.outgoing[i].name = Okay;
				manager.outgoing[i].sender = 0;
			}
		}else
		{
			manager.outgoing[i].name = Okay;
			manager.outgoing[i].sender = 0;
		}
	}
	Release(loopLock);
	
	manager.msgsToSend = NUM_FOOD_CLERKS;
	manager.state = CHECKSENDFOODCLERKS;
}

void Manager_ChSFC()
{
	if(manager.cgSize == 0)
	{
		manager.state = AVAILABLE;
		Release(foodLinesLock);
	}else{
		manager.replyTo = manager.currentGroup[manager.cgSize-1];
		if(manager.outgoing[manager.cgSize-1].name == GoOnBreak)
		{
			/*printf("Manager has told TicketClerk %s to go on break.\n",((TicketClerk*)replyTo)->myName);*/
		}
		/*((TicketClerk*)replyTo)->SendMessage(outgoing->GetName(0), 0);*/
		/*outgoing->Pop(0);*/
		SendMessage(T_FOODCLERK, manager.replyTo, manager.outgoing[manager.cgSize-1].name, 0);
		manager.cgSize = manager.cgSize - 1;
		manager.checkQueueSize = manager.checkQueueSize -1;
	}
}

void Manager_ChATT()
{
	manager.replyTo = manager.msgsToSend-1;
	/*((TicketClerk*)replyTo)->SendMessage("WhatIsStatus", 1, this);*/
	SendMessage(T_TICKETTAKER, manager.replyTo, WhatIsStatus, 0);
	manager.msgsToSend = manager.msgsToSend - 1;
	if(manager.msgsToSend == 0){
		manager.state = CHECKWAITTIXTAKERS;
	}
}

void Manager_ChWTT()
{
	Acquire(manager.msgLock);
	/*IterList* clerkMsg = msgList->Find("NumInLine");*/
	Manager_GetMessage(NumInLine);
	if(manager.tempMsg.sender != NullMsg)
	{
		Release(manager.msgLock);
		/*currentGroup->Append(clerkMsg->Get(0));*/
		manager.currentGroup[manager.cgSize] = manager.tempMsg.sender;
		manager.lineLengths[manager.cgSize] = Line_getSize(T_TICKETTAKER, manager.tempMsg.sender);
		manager.repliesWaiting = manager.repliesWaiting - 1;		
		if(manager.repliesWaiting == 0)
		{
			Acquire(entryLinesLock);
			manager.state = CHECKHANDLETIXTAKERS;
		}
	}else{
		Wait(manager.sleepCon, manager.msgLock);
	}
}

void Manager_ChHTT()
{
	/*Build Outgoing Queue*/
	/*indices of changed clerk*/
	int changedClerk=-1;
	int currLen = 0;
	int currTT;
	Acquire(loopLock);
	for(i = 0; i < NUM_TIX_TAKERS; i++)
	{	
		currTT = manager.currentGroup[i];
		currLen = manager.lineLengths[i];
		
		/*printf("Curr line length %d\n",currLen);*/
		
		if(currLen == 0 && changedClerk == -1)
		{
			if(getRandPercent() < 20)
			{
				/*outgoing->Append("GoOnBreak",0);*/
				manager.outgoing[i].name = GoOnBreak;
				manager.outgoing[i].sender = 0;
				changedClerk = i;
			}else{
				/*outgoing->Append("Okay",0);*/
				manager.outgoing[i].name = Okay;
				manager.outgoing[i].sender = 0;
			}
		}
		else if(currLen == -1 && changedClerk == -1)
		{
			/*printf("BREEEEEEEEEEEEEEEEEAK\n");*/
			for(k = 0; k < NUM_TIX_TAKERS; k++) /*see if anyone is overfull*/
			{
				if(i==k) continue;
				if(manager.lineLengths[k] > 5)/*if another line has more than 5 in it*/
				{
					/*outgoing->Append("ComeOffBreak",0);*/
					manager.outgoing[i].name = ComeOffBreak;
					manager.outgoing[i].sender = 0;
					changedClerk = i;
					break;
				}
			}
			/*no one overfull*/
			if(changedClerk == -1)
			{
				/*outgoing->Append("Okay",0);*/
				manager.outgoing[i].name = Okay;
				manager.outgoing[i].sender = 0;
			}
		}
		else if(currLen < 3 && changedClerk == -1)
		{
			for(k = 0; k < NUM_TIX_TAKERS; k++) /*see if anyone else is on duty*/
			{
				if(i==k) continue;
				if(manager.lineLengths[k] > 0) /*if another is working and can't be put on break*/
				{
					if(getRandPercent() < 20)
					{
						/*outgoing->Append("GoOnBreak",0);*/
						manager.outgoing[i].name = GoOnBreak;
						manager.outgoing[i].sender = 0;
						changedClerk = i;
						break;
					}
				}
			}
			if(changedClerk == -1)
			{
				/*outgoing->Append("Okay",0);*/
				manager.outgoing[i].name = Okay;
				manager.outgoing[i].sender = 0;
			}
		}else
		{
			manager.outgoing[i].name = Okay;
			manager.outgoing[i].sender = 0;
		}
	}
	Release(loopLock);
	
	manager.msgsToSend = NUM_TIX_TAKERS;
	manager.state = CHECKSENDTIXTAKERS;
}

void Manager_ChSTT()
{
	if(manager.cgSize == 0)
	{
		manager.state = IDLE;
		Release(entryLinesLock);
	}else{
		manager.replyTo = manager.currentGroup[manager.cgSize-1];
		if(manager.outgoing[manager.cgSize-1].name == GoOnBreak)
		{
			/*printf("Manager has told TicketClerk %s to go on break.\n",((TicketClerk*)replyTo)->myName);*/
		}
		/*((TicketClerk*)replyTo)->SendMessage(outgoing->GetName(0), 0);*/
		/*outgoing->Pop(0);*/
		SendMessage(T_TICKETTAKER, manager.replyTo, manager.outgoing[manager.cgSize-1].name, 0);
		manager.cgSize = manager.cgSize - 1;
		manager.checkQueueSize = manager.checkQueueSize -1;
	}
}

void Manager_CaATC()
{
	manager.replyTo = manager.msgsToSend-1;
	/*((TicketClerk*)replyTo)->SendMessage("GiveMeMoney", 1, this);*/
	SendMessage(T_TICKETCLERK, manager.replyTo, GiveMeMoney, 0);
	manager.msgsToSend = manager.msgsToSend - 1;
	if(manager.msgsToSend == 0)
	{
		manager.state = CASHWAITTIXCLERKS;
	}
}

void Manager_CaWTC()
{
	Acquire(manager.msgLock);
	/*IterList* clerkMsg = msgList->Find("HereIsMoney");*/
	Manager_GetMessage(HereIsMoney);
	if(manager.tempMsg.sender != NullMsg)
	{
		Release(manager.msgLock);
		manager.tixCash = manager.tixCash + tixClerks[manager.tempMsg.sender].moneyCollected;
		tixClerks[manager.tempMsg.sender].moneyCollected = 0;
		/*printf("Manager collected %.2f from %s.\n",clerkMsg->GetFloat(1),((TicketClerk*)clerkMsg->Get(0))->myName);*/
		manager.repliesWaiting = manager.repliesWaiting - 1;
		manager.checkQueueSize = manager.checkQueueSize -1;
		/*printf("replies awaiting %i\n",repliesWaiting);*/
		if(manager.repliesWaiting == 0)
		{
			manager.state = AVAILABLE;
			/*printf("state %s\n",state);*/
		}
	}else{
		Wait(manager.sleepCon, manager.msgLock);
	}
}

void Manager_CaAFC()
{
	manager.replyTo = manager.msgsToSend-1;
	/*((TicketClerk*)replyTo)->SendMessage("GiveMeMoney", 1, this);*/
	SendMessage(T_FOODCLERK, manager.replyTo, GiveMeMoney, 0);
	manager.msgsToSend = manager.msgsToSend - 1;
	if(manager.msgsToSend == 0)
	{
		manager.state = CASHWAITFOODCLERKS;
	}
}

void Manager_CaWFC()
{
	Acquire(manager.msgLock);
	/*IterList* clerkMsg = msgList->Find("HereIsMoney");*/
	Manager_GetMessage(HereIsMoney);
	if(manager.tempMsg.sender != NullMsg)
	{
		Release(manager.msgLock);
		manager.foodCash = manager.foodCash + foodClerks[manager.tempMsg.sender].moneyCollected;
		foodClerks[manager.tempMsg.sender].moneyCollected = 0;
		/*printf("Manager collected %.2f from %s.\n",clerkMsg->GetFloat(1),((TicketClerk*)clerkMsg->Get(0))->myName);*/
		manager.repliesWaiting = manager.repliesWaiting - 1;
		manager.checkQueueSize = manager.checkQueueSize -1;
		/*printf("replies awaiting %i\n",repliesWaiting);*/
		if(manager.repliesWaiting == 0)
		{
			manager.state = AVAILABLE;
			/*printf("state %s\n",state);*/
		}
	}else{
		Wait(manager.sleepCon, manager.msgLock);
	}
}

void Manager_CaCTT()
{
	/*printf("Total money made by office = %f .\n",tixCash+foodCash);*/
	manager.checkQueueSize = 0;
	manager.state = IDLE;
}
